package com.danco.training.zaneuskaya.connection.dao.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.danco.training.zaneuskaya.connection.dao.AbstractHibernateDao;
import com.danco.training.zaneuskaya.connection.dao.AuditorDao;
import com.danco.training.zaneuskaya.domain.Auditor;
import com.danco.training.zaneuskaya.domain.Order;



public class AuditorDaoImpl extends AbstractHibernateDao<Auditor, Integer> implements AuditorDao{

	@Override
	public Auditor read(Session session, Integer PK) throws HibernateException {
		return (Auditor) super.read(session, Auditor.class, PK);
	}

	@Override
	public List<Auditor> readAll(Session session) throws HibernateException {
		return super.readAll(Auditor.class, session);
	}

	@Override
	public List<Auditor> readAuditsSortedByDate(Session session, Date from,
			Date to) throws HibernateException {
		Criteria criteria = session.createCriteria(Auditor.class);
		criteria.add(Restrictions.between("auditTime", from,to));
		return criteria.list();
	}

	@Override
	public List<Auditor> readAuditsSortedByDate(Session session) {
		Criteria criteria = session.createCriteria(Auditor.class);
		criteria.addOrder(org.hibernate.criterion.Order.asc("auditTime"));
		return criteria.list();
	}

}
